#include <iostream>

来源:百度知道 编辑:UC知道 时间:2024/05/06 04:46:26
#include <iostream>
using namespace std;
#include "stdio.h"
#include "stdlib.h"
#define Null 0
typedef char Elemtype;
typedef struct LNode{
Elemtype data;
struct LNode *next;
}LinkList;
LinkList *P,*L;
int m=sizeof(LinkList);
void Create(char i){
*L=malloc(m);
P=L;
for(i='A';i<'Z';++i){
P->data=i;
P->next=malloc(m);
P=P->next;
P->data='z';
P->next=Null;

}
};
int main()
{void CreateList_L(char i);
return 0;
}
请教高手错在那里啊。

老大 ,首先不得不说你写的程序只在太难看了(注意格式啊).
你要改的是这两句 :
*L=malloc(m); 应该改成 L=(LinkList *)malloc(m);
P->next=malloc(m); 应该改为: p->next=(LinkList *)malloc(m);
这样就可以了.
告诉你,malloc函数它分配的空间类型默认是void的,也就是一个void *的指针指向该空间,你需要进行强制转换.